package pkg

import (
	"fmt"
	"github.com/boombuler/barcode"
	"github.com/boombuler/barcode/qr"
	"hr/config"
	"image/png"
	"os"
)

func GeneraQrcode(code, name string) (string, error) {
	qrCode, err := qr.Encode(code, qr.M, qr.Auto)
	if err != nil {
		return "", err
	}
	qrCode, err = barcode.Scale(qrCode, 256, 256)
	if err != nil {
		return "", err
	}
	filePath := config.AppConfig.Static.CacheDir + "/qrcode"
	fileName := fmt.Sprintf("%s/%s.png",filePath, name)
	file, err := os.Create(fileName)
	defer file.Close()
	if err != nil {
		return "", err
	}
	_ = png.Encode(file, qrCode)
	return fileName, nil
}
